﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HNQXYJ.Model;
using System.Data;
using System.Data.SqlClient;

namespace HNQXYJ.DAL
{
    public class EquipOnLineDAL
    {
        /// <summary>
        /// 在快1点的时候向设备表（EquipOnLine表中插入一条新的数据，）
        /// </summary>
        /// <param name="eo"></param>
        /// <param name="flage">标示终端的状态 1 在线，0 离线</param>
        /// <returns></returns>
        public int AddDataOnTime00(EquipOnline eo,string flage)
        {
            string procName = "EquipOnLineAddData00";
            SqlParameter[] paras = { 
                                  new  SqlParameter("@Phone",SqlDbType.VarChar,50),
                                  new  SqlParameter("@DateAdd",SqlDbType.VarChar,50),                                
                                  new SqlParameter ("@Status",SqlDbType.VarChar,50)
                                   };
            paras[0].Value = eo.Phone;
            paras[1].Value = eo.DateAdd;           
            paras[2].Value = flage;
            int res = SqlHelper.ExecNonQuery(procName, paras);
            return res;
        }

        /// <summary>
        /// 一点以后就要对表中数据进行更新
        /// </summary>
        /// <param name="eo"></param>
        /// <param name="hourNum">用来表示当前是几点</param>
        /// <returns></returns>
        public int UpdateOnHour(EquipOnline eo ,int hourNum)
        {
            string procName = "EquipOnLineUpdateOneHour";
            SqlParameter[] paras = { 
                                   new SqlParameter("@Phone",SqlDbType.VarChar,50),
                                   new SqlParameter("@DateAdd",SqlDbType.VarChar,50),
                                   new SqlParameter("@HourNum",SqlDbType.Int )
                                   };

            paras[0].Value = eo.Phone;
            paras[1].Value = eo.DateAdd;
            paras[2].Value = hourNum;
            int res = SqlHelper.ExecNonQuery(procName, paras);
            return res;
        }

        /// <summary>
        /// 判断设备状态表中是否存在当前日期下的数据 
        /// </summary>
        /// <param name="eo"></param>
        /// <returns></returns>
        public int IsHavePhoneAndDateAdd(EquipOnline eo)
        {
            string procName = "EquipOnlineIsHavePhoneAndDateAdd";
            SqlParameter[] paras = { 
                                   new SqlParameter("@Phone",SqlDbType.VarChar,50),
                                   new SqlParameter("@DateAdd",SqlDbType.VarChar,50)
                                   };
            paras[0].Value = eo.Phone;
            paras[1].Value = eo.DateAdd;

            int count = Convert.ToInt32( SqlHelper.ExecuteScalar(procName, paras));

            return count;
        }
    }
}